package com.lagou.boot;

import java.util.concurrent.atomic.AtomicLong;

import com.lagou.client.RPCConsumer;
import com.lagou.request.RpcRequest;
import com.lagou.service.IUserService;

public class ConsumerBoot {

    // 参数定义
    private static final String PROVIDER_NAME = "UserService#sayHello#";

    private static final AtomicLong requestId = new AtomicLong(0);

    public static void main(String[] args) throws InterruptedException {

        // 1.创建代理对象
        RpcRequest rpcRequest = new RpcRequest();
        rpcRequest.setClassName(IUserService.class.getName());
        rpcRequest.setMethodName("sayHello");
        rpcRequest.setParameters(new Object[] {"来自客户端的请求"});
        rpcRequest.setRequestId(requestId.incrementAndGet() + "");
        rpcRequest.setParameterTypes(new Class[] {String.class});
        IUserService service = (IUserService)RPCConsumer.createProxy(IUserService.class, rpcRequest);

        // 2.循环给服务器写数据
        while (true) {
            String result = service.sayHello("hello rpc server");
            System.out.println("收到服务端的回应：" + result);
            Thread.sleep(2000);
        }

    }
}
